package com.zt.bus.line.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zt.bus.line.inter.VehicleMapper;
import com.zt.bus.line.model.Vehicle;
import com.zt.servlet.ReqBean;
import com.zt.system.model.SqlBuilder;
import com.zt.system.service.BaseService;
import com.zt.util.DateUtil;

import net.sf.json.JSONObject;

@Service
public class VehicleService extends BaseService {

    @Autowired
    private VehicleMapper vehicleMapper;

    /**
     * 查询
     *
     * @param reqBean
     * @return
     */
    public JSONObject findBus(ReqBean reqBean) {
        SqlBuilder sqlBuilder = new SqlBuilder("", new Object[0]);
        return this.queryTable(sqlBuilder, reqBean.getPageSize(), reqBean.getPageIndex());
    }

    /**
     * 查询全部车辆信息
     * @return
     */
    public List<Vehicle> getAllVehicle(){
    	return vehicleMapper.selectAll();
    }
    
    /**
     * 通过车牌查询车辆
     * @return
     */
    public Vehicle getByVehicleNo(String vehicleNo){
    	return vehicleMapper.selectByVehicleNo(vehicleNo);
    }
    

    /**
     * 从表单获取对象
     *
     * @param reqBean
     * @return
     */
    private Vehicle getVehicle(ReqBean reqBean) {
    	Vehicle vehicle = new Vehicle();

    	vehicle.setId(reqBean.getInfo("id"));
    	vehicle.setVehicleNo(reqBean.getInfo("vehicleNo"));
    	vehicle.setSeatNum(reqBean.getInfoInt("seatNum"));
    	vehicle.setVehicleName(reqBean.getInfo("vehicleName"));
    	vehicle.setVehicleType(reqBean.getInfo("vehicleType"));
    	vehicle.setOperator(reqBean.getUserId());
    	vehicle.setMakeTime(DateUtil.parseDateTime(reqBean.getInfo("makeTime")));
    	vehicle.setModifyTime(new Date());
    	vehicle.setRemark(reqBean.getInfo("remark"));

        return vehicle;
    }

}